package com.hyjiacan.apps.audionly.data.model

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.assertThrows

/**
 * AudioParam实体类的单元测试
 */
class AudioParamTest {
    @Test
    fun `test AudioParam creation with default values`() {
        // 使用默认值创建对象
        val audioParam = AudioParam()

        // 验证默认属性值
        assertEquals(128, audioParam.bitRate)
        assertEquals(44100, audioParam.sampleRate)
        assertEquals(2, audioParam.channels)
        assertEquals("mp3", audioParam.format)
        assertEquals(5, audioParam.quality)
    }

    @Test
    fun `test AudioParam creation with custom values`() {
        // 使用自定义值创建对象
        val audioParam = AudioParam(
            bitRate = 256,
            sampleRate = 48000,
            channels = 1,
            format = "wav",
            quality = 8
        )

        // 验证自定义属性值
        assertEquals(256, audioParam.bitRate)
        assertEquals(48000, audioParam.sampleRate)
        assertEquals(1, audioParam.channels)
        assertEquals("wav", audioParam.format)
        assertEquals(8, audioParam.quality)
    }

    @Test
    fun `test AudioParam copy method`() {
        // 创建原始对象
        val original = AudioParam(
            bitRate = 256,
            sampleRate = 48000,
            channels = 1,
            format = "wav",
            quality = 8
        )

        // 测试部分属性修改的复制
        val copied = original.copy(
            bitRate = 320,
            format = "flac"
        )

        // 验证复制后的对象
        assertEquals(320, copied.bitRate)
        assertEquals(original.sampleRate, copied.sampleRate)
        assertEquals(original.channels, copied.channels)
        assertEquals("flac", copied.format)
        assertEquals(original.quality, copied.quality)
    }

    @Test
    fun `test AudioParam invalid parameters`() {
        // 测试无效的比特率
        assertThrows<IllegalArgumentException> { AudioParam(bitRate = 0) }

        // 测试无效的采样率
        assertThrows<IllegalArgumentException> { AudioParam(sampleRate = 0) }

        // 测试无效的声道数
        assertThrows<IllegalArgumentException> { AudioParam(channels = 0) }

        // 测试无效的质量值
        assertThrows<IllegalArgumentException> { AudioParam(quality = 0) }
        assertThrows<IllegalArgumentException> { AudioParam(quality = 11) }
    }
}